| Conditions | 19 | 
| Total Lines | 54 | 
| Code Lines | 40 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like helper.ts ➔ sortRankings often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import { RankingDataTeamObject } from "../Types/Ranking" | 
            ||
| 24 | |||
| 25 | export function sortRankings(a: RankingDataTeamObject, b: RankingDataTeamObject) { | 
            ||
| 26 | // Rank lager: A stijgt in sortering.  | 
            ||
| 27 |   if (a.rank < b.rank) { | 
            ||
| 28 | return -1  | 
            ||
| 29 | }  | 
            ||
| 30 |   if (a.rank > b.rank) { | 
            ||
| 31 | return 1  | 
            ||
| 32 | }  | 
            ||
| 33 | // Aantal overwinningen hoger: A stijgt in sortering.  | 
            ||
| 34 |   if (a.wins > b.wins) { | 
            ||
| 35 | return -1  | 
            ||
| 36 | }  | 
            ||
| 37 |   if (a.wins < b.wins) { | 
            ||
| 38 | return 1  | 
            ||
| 39 | }  | 
            ||
| 40 | // Doelpuntensaldo beter: A stijgt in sortering.  | 
            ||
| 41 |   if (a.goalsScored - a.goalsConceded > b.goalsScored - b.goalsConceded) { | 
            ||
| 42 | return -1  | 
            ||
| 43 | }  | 
            ||
| 44 |   if (a.goalsScored - a.goalsConceded < b.goalsScored - b.goalsConceded) { | 
            ||
| 45 | return 1  | 
            ||
| 46 | }  | 
            ||
| 47 | // Aantal gemaakte doelpunten hoger: A stijgt in sortering.  | 
            ||
| 48 |   if (a.goalsScored > b.goalsScored) { | 
            ||
| 49 | return -1  | 
            ||
| 50 | }  | 
            ||
| 51 |   if (a.goalsScored < b.goalsScored) { | 
            ||
| 52 | return 1  | 
            ||
| 53 | }  | 
            ||
| 54 | // Aantal uitoverwinningen hoger: A stijgt in sortering.  | 
            ||
| 55 |   if (a.winsAway > b.winsAway) { | 
            ||
| 56 | return -1  | 
            ||
| 57 | }  | 
            ||
| 58 |   if (a.winsAway < b.winsAway) { | 
            ||
| 59 | return 1  | 
            ||
| 60 | }  | 
            ||
| 61 | // Doelpuntensaldo op verplaatsing beter: A stijgt in sortering.  | 
            ||
| 62 |   if (a.goalsScoredAway - a.goalsConcededAway > b.goalsScoredAway - b.goalsConcededAway) { | 
            ||
| 63 | return -1  | 
            ||
| 64 | }  | 
            ||
| 65 |   if (a.goalsScoredAway - a.goalsConcededAway < b.goalsScoredAway - b.goalsConcededAway) { | 
            ||
| 66 | return 1  | 
            ||
| 67 | }  | 
            ||
| 68 | // Aantal gemaakte doelpunten op verplaatsing hoger: A stijgt in sortering.  | 
            ||
| 69 |   if (a.goalsScoredAway > b.goalsScoredAway) { | 
            ||
| 70 | return -1  | 
            ||
| 71 | }  | 
            ||
| 72 |   if (a.goalsScoredAway < b.goalsScoredAway) { | 
            ||
| 73 | return 1  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 | return a.team?.club?.localName.localeCompare(b.team?.club?.localName)  | 
            ||
| 77 | }  | 
            ||
| 78 | |||
| 115 |